from selenium.webdriver.common.by import By
from pages.base_page import Page


class AutoDistributionPage(Page):
    ele_title = (By.ID, u'page-autoDistributionConfig-title')
    ele_feature_switch = (By.XPATH, u"//span[@data-tag='featureSwitch']")
    ele_method_form = (By.XPATH, u"//p[text()='Auto Distribution Method']")
    ele_save_button = (By.XPATH, u"//span[text()='Save']")

    # no feature
    ele_title_no_feature = (By.ID, u'undefined-title')
    ele_unlock_button = (By.XPATH, u'//button/span[text()="Unlock This Feature"]')

    ele_error = (By.XPATH, '//div[@role="alert"]')

    def __init__(self, driver, url, site_id):
        Page.__init__(self, driver, url)
        self.site_id = site_id
        self.url = url

    def check_is_enable_auto_distribution(self):
        fs = self.find_element(*self.ele_feature_switch)
        if fs.text == 'OFF':
            self.click(self.ele_feature_switch)
        else:
            pass

    def check_auto_distribution_page_when_has_auto_distribution_feature(self):
        self.find_element(*self.ele_title).is_enabled()
        # self.find_element(*self.ele_method_form).is_enabled()
        self.find_element(*self.ele_save_button).is_enabled()

    def check_auto_distribution_page_when_no_auto_distribution_feature(self):
        self.find_element(*self.ele_title_no_feature).is_enabled()
        self.find_element(*self.ele_unlock_button).is_enabled()
